﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Soul.XLS
{
    public class ExcelFooter
    {
        public List<ExcelFooterItem> Cells { get; }

        public int? Height { get; set; }

        public ExcelFooter(ExcelTable table)
        {
            Cells = table.Columns.Select(s => new ExcelFooterItem(s, null)).ToList();
        }

        public void SetData(string code, object value, Action<ExcelCellStyle> style = null)
        {
            var cell = GetCell(code);
            if (cell != null)
            {
                cell.Value = value;
                cell.Style = style;
            }
        }

        public void SetFormula(string code, string formula, Action<ExcelCellStyle> style = null)
        {
            SetData(code,new ExcelFormula(formula),style);
        }

        internal ExcelFooterItem GetCell(string code)
        {
            var cell = Cells.Where(a => a.Column.Code == code).FirstOrDefault();
            return cell;
        }
    }

    public class ExcelFooterItem : ExcelCell
    {
        internal Action<ExcelCellStyle> Style { get; set; }

        public ExcelFooterItem(ExcelColumn column, object value)
            : base(column, value)
        {
        }
    }
}
